package org.jeecg.modules.controller;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.entity.RunnerMatchPlayer;
import org.jeecg.modules.service.IRunnerMatchPlayerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author tanxy
 * @date 2023年02月28日 21:47
 */

@Api(tags = "赛事选手接口")
@Slf4j
@RestController
@RequestMapping("/matchplayer")
public class MatchPlayerController {

    @Autowired
    private IRunnerMatchPlayerService playerService;

    @AutoLog(value = "选手列表查询")
    @ApiOperation(value = "选手列表查询", notes = "根据比赛ID获取选手列表")
    @GetMapping(value = "/list")
    public Result list(@RequestParam(name="matchId") String matchId){
        List<RunnerMatchPlayer> players = playerService.selectByMainId(matchId);
        return Result.ok(players);
    }


    @AutoLog(value = "选手保存")
    @ApiOperation(value = "选手保存", notes = "根据选手保存选手信息")
    @PostMapping(value = "/save")
    public Result save(@RequestBody RunnerMatchPlayer matchPlayer){

        if(matchPlayer!=null&& StrUtil.isNotEmpty(matchPlayer.getId())){
            playerService.updateById(matchPlayer);
        }else {
            return Result.error("选手信息不能为空!");
        }
        return Result.ok(matchPlayer);
    }

}
